package com.stox.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stox.converter.BeanMapper;
import com.stox.manager.BarManager;
import com.stox.model.Bar;
import com.stox.model.entity.BarEntity;

@Controller
@RequestMapping(value="/bars")
public class BarController {

	@Autowired
	private BarManager barManager;
	
	@Autowired
	private BeanMapper beanMapper;

	@ResponseBody
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/{scripCode}", method=RequestMethod.GET, produces="application/json")
	public List<BarEntity> findByScripCode(@PathVariable("scripCode") String scripCode) {
		List<BarEntity> barEntities =  barManager.findByScripCode(scripCode);
		return beanMapper.map(barEntities, ArrayList.class, Bar.class);
	}
	
}
